import GreyReactBox from 'grey-react-box';

export class MyS {
    a: number = 0;
}

export default class Ms extends GreyReactBox<MyS> {

    // static _instance: Ms;

    // static get instance() {
    //     if (Ms._instance) {
    //         return Ms._instance;
    //     } else {
    //         return new Ms();
    //     }
    // }

    constructor() {
        super(new MyS());
        // Ms._instance = this;
    }

    setBox = this.action(async (s: MyS, add?: number) => {
        s.a = s.a + (add || 0)
        return s;
    })

    add = this.pipeline(async (box, o?: {a:string, b:number}) => {
        box.a++;
    })

    setBox2 = this.pipeline(
        (s: MyS, add?: number) => new Promise((resolve: (value?: any) => void) => {
            setTimeout(() => {
                s.a = s.a + (add || 0)
                resolve();
            }, 2000)
        }),

        (s: MyS, add?: number) => new Promise((resolve: (value?: any) => void) => {
            setTimeout(() => {
                s.a = s.a + (add || 0)
                resolve();
            }, 2000)
        }),

        (s: MyS, add?: number) => new Promise((resolve: (value?: any) => void) => {
            setTimeout(() => {
                s.a = s.a + (add || 0);
                resolve(s)
            }, 2000)
        }),

        (s: MyS, add?: number) => new Promise((resolve: (value?: any) => void) => {
            setTimeout(() => {
                s.a = s.a + (add || 0)
                resolve(s)
            }, 2000)
        }),
    )
}
